'use strict'
const fs = require('fs');
const fastq = require('./queue');
const process = require("child_process");

const excuteBuildTask = (arg, cb) => {
    const time = Date.now();
    process.exec("npm run build",(error,stdout,stderr)=>{
        if(error){
            cb(error);
            return
        }
        cb(null, "build successfully!")
    })
}

const buildQueue = fastq(excuteBuildTask, 1)


const addBuildTask = (task) => {
    buildQueue.push(task, function (err, result) {
        buildQueue.getQueue()
        console.log('buildQueue.getQueue(): ', buildQueue.getQueue());
        if (err) { throw err }
        console.log('the result is', result)
    })
}

buildQueue.error((err,task)=>{
});

buildQueue.drain = ()=>{
}

module.exports = { addBuildTask };


